<?php

namespace System\library\error\observers;

use System\library\config\Config;

/**
 * <b>Class</b> :        Display<br>
 * <b>Fonction</b> :     Observer "Display" permet d'afficher une erreur ou une exception
 * <br>
 * @version              1.0
 * @author               Dread <dreadlokeur@gmail.com>
 * @license              Licence publique générale GNU http://www.gnu.org/licenses/gpl.html
 * @copyright            Copyright 2011 - MidichloriansPHP and contributors
 * @package              System
 * @subpackage           library\error\observers
 *
 * @see \SplObserver
 */
class Display implements \SplObserver {

    public function __construct() {

    }

    public function update(\SplSubject $subject, $isException = false) {
        if (!$isException) {
            //$error = $this->_formater->format($subject->getError());
            $error = $subject->getError();
            if (Config::isDefinedCons('PATH_TOOL') && file_exists(Config::getCons('PATH_TOOL') . 'debugger' . DIRECTORY_SEPARATOR . 'php_error.tpl.php'))
                require_once Config::getCons('PATH_TOOL') . 'debugger' . DIRECTORY_SEPARATOR . 'php_error.tpl.php';
            else
                echo '<b>' . $error->type . '</b> : ' . $error->message . ' in <b>' . $error->file . '</b> on line <b>' . $error->line . '</b>';
        } else {
            //$exception = $this->_formater->format($subject->getException());
            $exception = $subject->getException();
            if (Config::isDefinedCons('PATH_TOOL') && file_exists(Config::getCons('PATH_TOOL') . 'debugger' . DIRECTORY_SEPARATOR . 'exception.tpl.php'))
                require_once Config::getCons('PATH_TOOL') . 'debugger' . DIRECTORY_SEPARATOR . 'exception.tpl.php';
            else
                echo '<b> ' . $exception->type . ' </b> : "' . $exception->message . '" in <b>' . $exception->file . '</b> on line <b>' . $exception->line . '</b> with trace : ' . $exception->trace;
        }
    }

}

?>
